package com.hnkywl.sts.action.base;

import com.hnkywl.sts.entity.base.Xtgg;
import com.hnkywl.sts.service.base.XtggService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-3-29
 * Time: 下午9:48
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/base/xtgg")
public class XtggAction extends SimpleActionSupport {
    private Xtgg xtgg;

    // 公告标题
    private String ggbt;

    // 公告内容
    private String ggnr;

    // 公告状态
    private String ggzt;

    // 创建开始时间
    private Date xtggcjStart;

    // 创建结束时间
    private Date xtggcjEnd;

    //公告只读状态
    private boolean xtggReadonly;
    private String gsjgId;

    private int page;
    private int rows = 10;

    private XtggService xtggService;

    @Action("xtgg_list")
    public void xtggList() {
        this.renderJson(this.xtggService.findAllXtgg(ggbt, ggnr, ggzt, xtggcjStart, xtggcjEnd, page, rows));
    }

    @Action("xtgg_save")
    public void save() {
        try {
            this.xtggService.save(xtgg);
            renderText("{\"statusCode\":\"200\",\"message\":\"保存成功!\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("xtgggl_content")
    public String xgglContent() {
        if (xtgg != null && xtgg.getId() != null)
            xtgg = this.xtggService.get(xtgg.getId());
        return SUCCESS;
    }

    @Action("xtgg_del")
    public void xtggDel() {
        try {
            this.xtggService.delete(xtgg);
            renderText("{\"statusCode\":\"200\",\"message\":\"删除成功!\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("xtgg_top")
    public void xtggTop(){
        try {
            this.xtggService.top(xtgg,true);
            renderText("{\"statusCode\":\"200\",\"message\":\"置顶成功!\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("xtgg_untop")
    public void xtggUntop(){
        try {
            this.xtggService.top(xtgg,false);
            renderText("{\"statusCode\":\"200\",\"message\":\"取消置顶成功!\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("xtgg_pub")
    public void xtggPub() {
        try {
            this.xtggService.publish(xtgg,gsjgId);
            renderText("{\"statusCode\":\"200\",\"message\":\"发布成功!\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("xtgg_unpub")
    public void xtggUnpub() {
        try {
            this.xtggService.unPublish(xtgg);
            renderText("{\"statusCode\":\"200\",\"message\":\"取消发布成功!\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Autowired
    public void setXtggService(XtggService xtggService) {
        this.xtggService = xtggService;
    }

    public String getGsjgId() {
        return gsjgId;
    }

    public void setGsjgId(String gsjgId) {
        this.gsjgId = gsjgId;
    }

    public String getGgbt() {
        return ggbt;
    }

    public void setGgbt(String ggbt) {
        this.ggbt = ggbt;
    }

    public String getGgnr() {
        return ggnr;
    }

    public void setGgnr(String ggnr) {
        this.ggnr = ggnr;
    }

    public String getGgzt() {
        return ggzt;
    }

    public void setGgzt(String ggzt) {
        this.ggzt = ggzt;
    }

    public Date getXtggcjStart() {
        return xtggcjStart;
    }

    public void setXtggcjStart(Date xtggcjStart) {
        this.xtggcjStart = xtggcjStart;
    }

    public Date getXtggcjEnd() {
        return xtggcjEnd;
    }

    public void setXtggcjEnd(Date xtggcjEnd) {
        this.xtggcjEnd = xtggcjEnd;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public Xtgg getXtgg() {
        return xtgg;
    }

    public void setXtgg(Xtgg xtgg) {
        this.xtgg = xtgg;
    }

    public boolean getXtggReadonly() {
        return xtggReadonly;
    }

    public void setXtggReadonly(boolean xtggReadonly) {
        this.xtggReadonly = xtggReadonly;
    }
}
